import allroutes from "../router/allroutes";
// 动态创建
export const generatorRouters = (roles) =>
  roles.map(({
    name,
    children = []
  }) => {
    return {
      path: "/" + name,
      name: name,
      component: () => import(`../pages/${name}/${name}.vue`),
      children: generatorRouters(children),
    };
  });

// 字典查询
// 时间复杂度 O(n^2) 哈希表 {}
/* export const queryDictionaries = (roles) =>
  allroutes.filter((route) => {
    let _route = {};
    roles.forEach((r) => {
      if (r.name == route.name) {
        _route = route;
      }
    });
    return _route;
  }); */
export const queryDictionaries = (roles) => roles.map((r) => allroutes[r.name]);
//  1  使其与data格式相同  传感器数量
export const formatgetSensorData = (arr) => {
  // for (let i = 0; i < 6; i++) {
  //   if (arr.length >= 6) {
  //     break;
  //   }
  //   arr.unshift(0);
  // }
  while(arr.length <6){
    arr.unshift(0)
  }
  return arr;
};